What is @aws-crypto/sha256-js?
The @aws-crypto/sha256-js package is a JavaScript implementation of the SHA-256 hash function. It is part of the AWS SDK for JavaScript and is used to compute SHA-256 cryptographic hash values. This package is particularly useful when working with AWS services that require SHA-256 hashes, such as signing requests for AWS Signature Version 4.
Computing SHA-256 hash
This feature allows you to compute the SHA-256 hash of a given input. The code sample demonstrates how to create a new instance of the Sha256 class, update it with the data to be hashed, and then compute the digest.
const { Sha256 } = require('@aws-crypto/sha256-js');
async function computeHash(data) {
const hash = new Sha256();
hash.update(data);
return hash.digest();
}
computeHash('data to hash').then(console.log);